package com.lsa.letcode.the125.validPalindrome;

import static org.junit.Assert.*;

import org.apache.commons.lang.StringUtils;
import org.junit.Test;

/**
 *"aman, a plan, a canal: Panama"
 */
public class ValidPalindromeTest {
	@Test
	public void test() throws Exception {
		testTrue("   ");
		testTrue(" a  ");
		testFalse(" am za  ");
		testTrue("aman, a plan, a canal: Panama");
		testFalse("aman, a plan, a zcanal: Panama");
		testTrue("ama");
		
		testFalse(" am mcma  ,,");
	}

	private void testTrue(String str) {
		test(str, true);
	}
	
	private void testFalse(String str) {
		test(str, false);
	}
	
	private void test(String str, boolean isTrue) {
		Solution s = new Solution();
		printCompare(str);
		assertEquals(isTrue, s.isPalindrome(str));
	}

	private void printCompare(String str) {
		String norm = normalize(str);
		String normReversed = StringUtils.reverse(norm);
		System.out.println(String.format("%s\n%s %s", norm, normReversed, norm.equals(normReversed)));
		System.out.println("--");
	}
	
	private String normalize(String s) {
		return s.toLowerCase().replaceAll("[^a-z0-9]+", "");
	}
	
}
